home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / msgq160s.arc / MSGLIST.C < prev    next >
Text File  |  1991-10-26  |  5KB  |  241 lines

  1. /*
  2.  * MSGLIST.C - Message header listing
  3.  *
  4.  * Msged/Q message editor for QuickBBS  Copyright 1990 by P.J. Muller
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include "msged.h"
  13. #include "screen.h"
  14. #include "qmsgbase.h"
  15.  
  16. static void update(int n,int y);
  17. static void showline(int y, BOOLEAN hi);
  18.  
  19. static char scrwidth[16];
  20. static BOOLEAN f = TRUE;
  21. static struct mh {
  22.        MSGHEADER h;
  23.        int n;
  24.      } *headers;
  25.  
  26. void list()
  27. {
  28.   int i, y, ch, a;
  29.   char *s;
  30.  
  31.   if (countmsg(CurBoard) < 1)    /* area is empty */
  32.     return;
  33.  
  34.   cls();
  35.   sprintf(scrwidth,"%%-%d.%ds",maxx,maxx);
  36.   i = a = curmsg(CurBoard);
  37.   headers = (struct mh *) calloc(maxy+1,sizeof(struct mh));
  38.  
  39.   y = 1;
  40.  
  41.   update(i,y);
  42.  
  43.   ch = 0;
  44.   y = 1;
  45.  
  46. /* this is still a mess */
  47.  
  48.   while ((ch != ENTER) && (ch != ABORT)) {
  49.     gotoxy(1, y);
  50.     clreol();
  51.     showline(y, TRUE);
  52.  
  53.     switch (ch = getkey()) {
  54.  
  55.       case HELP:
  56.     helplist();
  57.     update(a,1);
  58.     break;
  59.  
  60.       case KAREA :
  61.       case TOGGLE :
  62.     f = !f;
  63.     y = 1;
  64.     update(a,y);
  65.     break;
  66.  
  67.       case PGDN:
  68.     { int last = lastmsg(CurBoard);
  69.       i = maxy-y+1;
  70.       while ((--i > 0) && (a < last))
  71.         a = msgnext(CurBoard,a);
  72.     }
  73.  
  74.     y = 1;
  75.     update(a,y);
  76.     break;
  77.  
  78.       case PGUP:
  79.     { int first = firstmsg(CurBoard);
  80.       i = maxy-1;            /* go forward i messages */
  81.  
  82.       while ((i-- > 0) && (a > first))
  83.         a = msgprev(CurBoard, a);
  84.       if (a <= first)
  85.         y = 1;
  86.     }
  87.  
  88.     /* y = 1; */
  89.  
  90.     update(a,1);
  91.     break;
  92.  
  93.       case TOP:
  94.     a = firstmsg(CurBoard);
  95.     y = 1;
  96.     update(a,y);
  97.     break;
  98.  
  99.       case BOTTOM:
  100.     a = lastmsg(CurBoard);
  101.     y = 1;
  102.     update(a,y);
  103.     break;
  104.  
  105.       case UP:
  106.     if (a > firstmsg(CurBoard)) {
  107.       int b = a;
  108.       gotoxy(1, y);
  109.       clreol();
  110.       showline(y, FALSE);
  111.  
  112.       if ((a = msgprev(CurBoard,a)) == 0)
  113.         a = b;
  114.       else
  115.         y--;
  116.  
  117.       if (y < 1) {
  118.         y = 1;
  119.         scrolldown(1, 1, maxx, maxy, 1);
  120.         memmove((headers + 1),headers,(sizeof(struct mh) * maxy));
  121.         if (!readheader(a, &headers[0].h))
  122.           strcpy(headers[0].h.from, "read error");
  123.         s = strchr(headers[0].h.from,'\n');
  124.         if (s != NULL)
  125.           *s = EOS;
  126.             s = strchr(headers[0].h.to,'\n');
  127.         if (s != NULL)
  128.           *s = EOS;
  129.         headers[0].n = a;
  130.           } /* if */
  131.         } /* if */
  132.     break;
  133.  
  134.       case DOWN:
  135.     if (a < lastmsg(CurBoard)) {
  136.       int b = a;
  137.       gotoxy(1, y);
  138.       clreol();
  139.       showline(y, FALSE);
  140.  
  141.       if ((a = msgnext(CurBoard,a)) == 0)
  142.         a = b;
  143.       else
  144.         y++;
  145.  
  146.       if (y > maxy) {
  147.         y = maxy;
  148.         scrollup(1, 1, maxx, maxy, 1);
  149.         memmove(headers,(headers + 1),sizeof(struct mh) * (maxy));
  150.         if (!readheader(a, &headers[maxy-1].h))
  151.           strcpy(headers[maxy-1].h.from,"read error");
  152.         s = strchr(headers[maxy - 1].h.from,'\n');
  153.         if (s != NULL)
  154.           *s = EOS;
  155.             s = strchr(headers[maxy - 1].h.to,'\n');
  156.         if (s != NULL)
  157.           *s = EOS;
  158.             headers[maxy-1].n = a;
  159.           } /* if */
  160.         } /* if */
  161.     break;
  162.  
  163.       case ENTER:
  164.     setcur(CurBoard, a);
  165.     /* readmsg(&message, a); -- done in main */
  166.     ptrfree(headers);
  167.     return;
  168.  
  169.       case ABORT:
  170.     ptrfree(headers);
  171.     return;
  172.  
  173.       case DONE2:
  174.     cleanup();
  175.     break;
  176.  
  177.     } /* switch */
  178.   } /* while */
  179. } /* list */
  180.  
  181. /*
  182.  * Update the display from message number 'i' and y coordinate 'y'
  183.  */
  184.  
  185. static void update(int i,int y)
  186. {
  187.   int t;
  188.   char *s;
  189.  
  190.   clrwnd(1,y,maxx,maxy);
  191.   do {
  192.     gotoxy(1,y);
  193.     if (!readheader(i, &headers[y-1].h))
  194.       strcpy(headers[y-1].h.from,"read error");
  195.     s = strchr(headers[y - 1].h.from,'\n');
  196.     if (s != NULL)
  197.       *s = EOS;
  198.     s = strchr(headers[y - 1].h.to,'\n');
  199.     if (s != NULL)
  200.       *s = EOS;
  201.     headers[y-1].n = i;
  202.     showline(y++, FALSE);
  203.     i = msgnext(CurBoard,t = i);
  204.   } while ((i != 0) && (i != t) && (y <= maxy));
  205. } /* update */
  206.  
  207. static void showline(int y, BOOLEAN hi)
  208. {
  209.   char line[200];
  210.   char ato[20], afr[20];
  211.  
  212.   sprintf(afr,"%d/%d",headers[y - 1].h.orig_net,headers[y - 1].h.orig);
  213.   sprintf(ato,"%d/%d",headers[y - 1].h.dest_net,headers[y - 1].h.dest);
  214.  
  215. /* Templates:
  216. nnnnn: 1234567890123456@123456789 to 1234567890123456@123456789 1234567890123456
  217. nnnnn: 1234567890123456 to 1234567890123456 123456789012345678901234567890123456
  218. */
  219.   if (f && arealist[area].netmail)
  220.     sprintf(line,"%5d: %-16.16s@%-9.9s to %-16.16s@%-9.9s %-16.16s", /* 16 */
  221.         headers[y - 1].n,
  222.         headers[y - 1].h.from,
  223.         afr,
  224.         headers[y - 1].h.to,
  225.         ato,
  226.         headers[y - 1].h.subj);
  227.   else
  228.     sprintf(line,"%5d: %-16.16s to %-16.16s %-36.36s", /* 36 */
  229.         headers[y - 1].n,headers[y - 1].h.from,headers[y - 1].h.to,headers[y - 1].h.subj);
  230.  
  231.   if (hi)
  232.     set_color(co_hilite);
  233.   else if (strnicmp(username, headers[y-1].h.to, strlen(username)) == 0)
  234.     set_color(co_quote);
  235.   else set_color(co_normal);
  236.  
  237.   bprintf(scrwidth,line);        /* will limit to screen width */
  238.  
  239.   set_color(co_normal);
  240. } /* showline */
  241.